package thread;

/*
 * @author zzr
 * @date: 2025/03/29  16:33
 * @description:
 */
public class ThreadDemo15 {

    // t 线程把计算的结果放到 result 中
    private static long result = 0;

    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(() -> {
            for (long i = 1; i <= 50_0000_000L; i++) {
                result += i;
            }
        });
        Thread t2 = new Thread(() -> {
            for (long i = 50_0000_001L; i <= 100_0000_000L; i++) {
                result += i;
            }
        });

        t.start();
        t2.start();
        long beg = System.currentTimeMillis();
        t.join();
        t2.join();
        long end = System.currentTimeMillis();
        System.out.println("result = " + result);
        System.out.println("time = " + (end - beg) + "ms");
    }
}
